define([
    'jquery',
    'underscore',
    'backbone',
    //'text!templates/form/form_add_admin.html'
    ], function($, _, Backbone,loginTemplate){
        var $html_loadding = '<div class="caculation-report"><img style="margin-left:170px" src="'+$template_admincp_url+'img/standard/loaders/loading64.gif"/></div>';
        var translateView = Backbone.View.extend({
            el: $("#main"),
            initialize: function(){
				
            },
            events: {
                
            },
            
            index: function(){
                var url = location.href;
                if(typeof oTable != "undefined"){
                    $("#table_translate").dataTable().fnDestroy();
                }
                $file = $base_url+'assets/language/datatables/us.txt';
                
                oTable = $("#table_translate").dataTable({
                    "sDom": "<'row'<'col-lg-8'l><'col-lg-1 button_create'><'col-lg-3'f>r>t<'row'<'col-lg-6'i><'col-lg-6'p>>",
                    "sPaginationType": "bootstrap",
                    "bJQueryUI": false,
                    "bAutoWidth": false,
                    "oLanguage": {
                        "sUrl": $base_url+"public/templates/admincp/js/language/datatable.vn.txt"
                    },
                    "sScrollX": "100%",
                    //"sScrollXInner": "100%",
                    "bScrollCollapse": true,
                    "iDisplayLength": 10,
                    "iDisplayStart": 0,
                    "bProcessing": true,
                    "bRetrieve": true,
                    "aaSorting": [],
                    "bServerSide": true,
                    "sAjaxSource": url,
                    "fnServerData": function(sSource, aaData, fnCallback, oSetting){
                        if(typeof filters != "undefined"){
                            obj_tmp = new Object;
                            $.each(filters, function(name, value){
                                obj_tmp[name] = value;
                            });
                            aoData.push({
                                name: "myFilter",
                                value: JSON.stringify(obj_tmp)
                            });
                        }
                        $.ajax({
                            dataType: "JSON",
                            url: sSource,
                            type: "POST",
                            data: aaData,
                            success: function(rs){
                                data = rs;
                                fnCallback(rs);
                            }
                        });
                    },
                    "aoColumns": [
                        {
                            // "mData": "admin_name",
                            "sType": "string",
                            "swidth": "25%",
                            "sClass": "string",
                            "sName": "keyword",
                            "bSortable": false
                        },
                        {
                            // "mData": "admin_name",
                            "sType": "date",
                            "swidth": "25%",
                            "sClass": "string",
                            "sName": "translate_en",
                            "bSortable": false
                        },
                        {
                            // "mData": "admin_name",
                            "sType": "date",
                            "swidth": "25%",
                            "sClass": "string",
                            "sName": "translate_vn",
                            "bSortable": false
                        },
                        {
                            // "mData": "action",
                            "sType": "string",
                            "swidth": "3%",
                            "sClass": "center",
                            "bSortable": false
                        }
                    ],
                    fnInitComplete: function()
                    {
                        $(this).slideDown(200);
                        $(".button_create").html('<button class="btn btn-primary btn-create" type="button">Create New</button>');
                        $(".btn-create").click(function(){
                            window.location.href = $admincp_url+'translate/add';
                        });
                        
                    }
                });
                $('.dataTables_length select').uniform();
                $('.dataTables_paginate > ul').addClass('pagination');
            },

            add: function(){
                // Form Validate
                $("#form").validate({
                    ignore: null,
                    ignore: 'input[type="hidden"]',
                    rules: {
                        agree: "required"
                    },
                    submitHandler: function(form){
                        form.submit();
                    }
                });
            },

            edit: function(){
                // Form Validate
                $("#form").validate({
                    ignore: null,
                    ignore: 'input[type="hidden"]',
                    rules: {
                        agree: "required"
                    },
                    submitHandler: function(form){
                        form.submit();
                    }
                });
            },

            render: function(){
                if(typeof this[$app.action] != 'undefined'){
                    new this[$app.action];
                }
            }
        });
        return translateView = new translateView;
    });
